package com.zdxlz.fcmp.upms.api.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zdxlz.fcmp.upms.api.dto.SystemLogReqDto;
import com.zdxlz.fcmp.upms.api.entity.SystemLoginLog;
import com.zdxlz.fcmp.upms.api.mapper.SystemLoginLogMapper;
import com.zdxlz.fcmp.upms.api.service.ISystemLoginLogService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 系统登陆日志记录表(SystemLoginLog)表服务实现类
 *
 * @author makejava
 * @since 2025-03-17 16:27:35
 */
@Service
public class SystemLoginLogServiceImpl<T> extends ServiceImpl<SystemLoginLogMapper, SystemLoginLog> implements ISystemLoginLogService<T> {

    /**
     * 分页查询数据
     */
    @Override
    public Page<T> selectSystemLoginLog(Page<SystemLoginLog> page, SystemLogReqDto dto) {
        LambdaQueryWrapper<SystemLoginLog> queryWrapper = new LambdaQueryWrapper<>();
        if (ObjectUtil.isNotEmpty(dto)) {
            queryWrapper.eq(StrUtil.isNotBlank(dto.mobile()), SystemLoginLog::getLoginMobile, dto.mobile());
        }
        return ((Page<T>) baseMapper.selectPage(page, queryWrapper));
    }

    /**
     * 新增一条数据
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean insertSystemLoginLog(SystemLoginLog entity) {
        baseMapper.insert(entity);
        return true;
    }

    /**
     * 通过ID更新一条数据
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateSystemLoginLog(SystemLoginLog entity) {
        baseMapper.updateById(entity);
        return true;
    }

    /**
     * 通过ID删除一条或多条数据
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteSystemLoginLog(List<Integer> ids) {
        baseMapper.deleteByIds(ids);
        return true;
    }
}
